package com.fr.base.core.image4j.io;

import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;

public class LittleEndianInputStream extends DataInputStream
{
  public LittleEndianInputStream(InputStream paramInputStream)
  {
    super(paramInputStream);
  }

  public short readShortLE()
    throws IOException
  {
    int i = read();
    int j = read();
    if ((i < 0) || (j < 0))
      throw new EOFException();
    int k = (short)((j << 8) + (i << 0));
    return k;
  }

  public int readIntLE()
    throws IOException
  {
    int i = read();
    int j = read();
    int k = read();
    int l = read();
    if ((i < -1) || (j < -1) || (k < -1) || (l < -1))
      throw new EOFException();
    int i1 = (l << 24) + (k << 16) + (j << 8) + (i << 0);
    return i1;
  }

  public float readFloatLE()
    throws IOException
  {
    int i = readIntLE();
    float f = Float.intBitsToFloat(i);
    return f;
  }

  public long readLongLE()
    throws IOException
  {
    int i = readIntLE();
    int j = readIntLE();
    long l = (i << 32) + (j & 0xFFFFFFFF);
    return l;
  }

  public double readDoubleLE()
    throws IOException
  {
    long l = readLongLE();
    double d = Double.longBitsToDouble(l);
    return d;
  }

  public long readUnsignedInt()
    throws IOException
  {
    long l1 = readUnsignedByte();
    long l2 = readUnsignedByte();
    long l3 = readUnsignedByte();
    long l4 = readUnsignedByte();
    long l5 = l1 << 24 | l2 << 16 | l3 << 8 | l4;
    return l5;
  }

  public long readUnsignedIntLE()
    throws IOException
  {
    long l1 = readUnsignedByte();
    long l2 = readUnsignedByte();
    long l3 = readUnsignedByte();
    long l4 = readUnsignedByte();
    long l5 = l4 << 24 | l3 << 16 | l2 << 8 | l1;
    return l5;
  }
}